<template>
	<view class="article_list">
		
		<u-swiper class="uswiper" :list="list1" @change="change" @click="click"></u-swiper>
		<list-components :data="articlelist" @clickItem="getDetail" @clickItemCollect="collect"></list-components>
		<u-tabbar v-model="current" :list="tabbar" :mid-button="false"></u-tabbar>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		computed: {
			tabbar() {
				return this.$store.state.tabbar
			}
		},
		

		data() {
			return {
				list1: [],
				articlelist: [],
				page: 0,
				page_size: 10,
				current: 0
			}
		},
		methods: {
			getDataTop() {
				this.$u.get('/banner/json').then((res) => {
					for (var i = 0; i < res.data.length; i++) {
						var item = {
							image : res.data[i].imagePath
						};
						this.list1.push(item);
						
					}
					console.log('成功');
					// console.log('pageIndex:'+this.pageIndex);
				}).catch((res) => {
					console.log('失败');
				})
			},

			getData() {
				console.log(this.page + ":" + this.page_size);
				// + '&page_size=' + this.page_size
				this.$u.get('/article/list/0/json?curPage=' + this.page + '&page_size=' + this.page_size).then((res) => {
					// res.article.forEach((item) => {
					// 	// item.coverImg = decodeURIComponent(item.bookCover[0]).replace('/agent/', '');
					// 	item.coverImg = decodeURIComponent(item.cover).replace('/agent/', '')
					// })
					// this.articlelist = [...this.articlelist, ...res.data.datas]
					if(this.page == 0){
						this.articlelist = []
					}
					this.articlelist = [...this.articlelist, ...res.data.datas]
					console.log('成功');
					// console.log('pageIndex:'+this.pageIndex);
				}).catch((res) => {
					console.log('失败');
				})

			},
			getDetail(data){
				console.log(data.link);
				uni.navigateTo({
					url:'../webview/webview?url='+data.link
				})
			},
			collect(data){
				if(data.collect){
					this.$refs.uToast.show({
						title: '取消收藏',
						type: 'success',
						duration: 1000,
					});
				}else{
					this.$refs.uToast.show({
						title: '收藏成功',
						type: 'success',
						duration: 1000,
					});
				}
			},
			
			change() {
				
			}
		},
		onLoad: function(option) {
			// this.page = option.page;
			// this.page_size = option.page_size;
			// this.articlelist = option.articlelist;
			this.getData();
			this.getDataTop();
		},
		onPullDownRefresh() {
			console.log('触发下拉刷新')
			this.page = 0;
			this.page_size = 10;
			this.articlelist = [];
			this.getData();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.page++;
			// this.page_size = this.page_size + 10;
			this.getData();
		}

	}
</script>

<style>
	.article_list {}
	.uswiper{
	}
</style>
